<template>
	<view class="route">
		<img src="../../static/logo.svg" class="logo" alt="" srcset="">
	</view>
</template>

<script>
	import {
		getSceneParam
	} from '../../api/scene'
	export default {
		data() {
			return {
				scene: undefined
			}
		},
		onLoad(option) {
			this.scene = option.scene
			this.login()
		},
		methods: {
			login() {

				uni.login({
					// #ifdef MP-WEIXIN
					provider: 'weixin', //使用微信登录
					// #endif
					// #ifdef MP-TOUTIAO
					provider: 'toutiao', //使用头条登录
					// #endif
					success: res => {
						console.log("uni.login", res)
						this.$store.dispatch('Login', {
							type: 2,
							data: {
								loginCode: res.code
									// #ifdef MP-WEIXIN
									,
								type: 34, //使用微信登录
								// #endif
								// #ifdef MP-TOUTIAO
								,
								type: 35, //使用字节登录
								// #endif
							}
						}).then(res => {
							// 加载用户信息
							this.$store.dispatch('ObtainUserInfo').then(result => {
								this.jumpNext()
							})



						})

					}
				})
			},
			jumpNext() {
				if (this.scene) {
					getSceneParam({
						code: this.scene
					}).then(result => {
						if (result.data) {
							console.log('getSceneParam', result.data.payload)
							var payload = JSON.parse(result.data.payload)
							payload.room.avatar = payload.avatar
							if (payload.mode === 1) {
								//参与者
								uni.setStorageSync("share", payload.room)
								uni.redirectTo({
									url: "/pages/index/index?scene=share"
								})
							} else if (payload.mode === 2) {
								uni.setStorageSync("share", payload.room)
								//观察者
								uni.redirectTo({
									url: "/pages/observerIndex/observerIndex?scene=share"
								})
							} else {
								uni.redirectTo({
									url: "/pages/index/index?scene=normal"
								})
							}
						} else {
							uni.redirectTo({
								url: "/pages/index/index?scene=normal"
							})
						}

					})
				} else {
					uni.redirectTo({
						url: "/pages/index/index?scene=normal"
					})
				}


			}
		}
	}
</script>

<style scoped lang="scss">
	.route {
		background-color: $uni-color-second;
		width: 100vw;
		height: 100vh;
		display: flex;
		align-items: center;
		justify-content: center;

		.logo {
			width: 80upx;
			animation: 5s hide 0s infinite;
		}

		@keyframes hide {
			0% {
				opacity: .1;
			}

			50% {
				opacity: .8;
			}

			100% {
				opacity: .1;
			}
		}


	}
</style>